class Solution {
public:
    vector<int> subsetSum;
    vector<int> path;
    void dfs(vector<int>& nums, int pos)
    {
        if (pos == nums.size())
        {
            int sum = 0;
            for (auto e : path)
                sum ^= e;
            subsetSum.push_back(sum);
            return;
        }

        path.push_back(nums[pos]);
        dfs(nums, pos + 1);
        path.pop_back();

        dfs(nums, pos + 1);
    }

    int subsetXORSum(vector<int>& nums) {
        int sum = 0;
        dfs(nums, 0);
        for (auto e : subsetSum)
            sum += e;
        return sum;
    }
};